home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Menus / MM / Design Notes Launch.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  3.4 KB  |  111 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //******************* GLOBALS **********************
  4.  
  5. var CMD_TO_LAUNCH = "Design Notes.htm";
  6.  
  7.  
  8. //***************** API  ******************
  9.  
  10. function canAcceptCommand() {
  11.   var retVal = true;             //always true for document window
  12.     
  13.   if (dw.getFocus(true) == 'site')  {
  14.     // getSiteSelFile() returns true if a single file or folder within the
  15.     // site is selected, and false if a drive or the site root folder 
  16.     // is selected.
  17.     retVal = (getSiteSelFile() != false); 
  18.     
  19.   }
  20.   else if (dw.getDocumentDOM() == null){
  21.     retVal = false;
  22.   }
  23.   
  24.   return retVal;
  25. }
  26.  
  27. //***************** LOCAL FUNCTIONS  ******************
  28.  
  29. function initializeUI() {
  30.   var filePath = "", src, metafile;
  31.  
  32.   MMNotes.UpdateSite = false;
  33.  
  34.   //ensure file is saved
  35.  
  36.   if (dw.getFocus(true) == 'site')
  37.   { //if called for site window
  38.     if (site.getFocus().toLowerCase() != "remote") { //local or map file selected
  39.       src = getSiteSelFile();
  40.       if (src) {                                   //single selection
  41.         var fObj = new File(src);
  42.         filePath = fObj.getAbsolutePath(); //resolve the local path of the selection
  43.         if (fObj.canWrite()) {
  44.           MMNotes.FileInfo_isWriteable = true;
  45.           MMNotes.UpdateSite = true;
  46.         }
  47.         else {
  48.           alert(MSG_ReadOnlyFile);
  49.           filePath = fObj.getAbsolutePath(); //resolve the local path of the selection
  50.           MMNotes.FileInfo_isWriteable = false;
  51.         }
  52.       }
  53.     } else {
  54.       alert(MSG_RemoteFileSel);
  55.     }
  56.  
  57.   } else {                        //called for doc window
  58.     filePath = dreamweaver.getDocumentPath("document");
  59.     if (!filePath) {
  60.       if (confirm(MSG_WantSave) && dw.canSaveDocument(dreamweaver.getDocumentDOM('document'))) {
  61.         dw.saveDocument(dreamweaver.getDocumentDOM('document'));
  62.         filePath = dreamweaver.getDocumentPath("document");
  63.       }
  64.     } else { //file exists, ensure it's writeable
  65.       var fObj = new File(filePath);
  66.       if (fObj.canWrite()) {
  67.         MMNotes.FileInfo_isWriteable = true;
  68.       }
  69.       else {
  70.         //filePath = "";           //clear, because we can't edit
  71.         MMNotes.FileInfo_isWriteable = false;
  72.         alert(MSG_ReadOnlyFile);
  73.       }
  74.  
  75.     }
  76.   }
  77.  
  78.   if (filePath) {
  79.     metafile = (MMNotes.open(filePath));  //open, or create metafile
  80.     if (metafile) {                            //if okay to open
  81.       MMNotes.close(metafile);                  //close it
  82.       MMNotes.FileInfo_filePath = filePath;     //store the filePath as a global
  83.       dreamweaver.popupCommand(CMD_TO_LAUNCH); //launch the command
  84.     } else {
  85.       if(!MMNotes.getSiteRootForFile(filePath)) { // if this file is not in a site
  86.         site.tryDefineOrEditSite("design notes"); // ask user to define or
  87.         return;                                   // edit site
  88.       }
  89.       alert(MSG_MetaDisabled);
  90.     }
  91.   }
  92. }
  93.  
  94.  
  95. function getSiteSelFile() {
  96.   var fileList = site.getSelection();
  97.   
  98.   // do not return true if the items selected are disk volumes, or
  99.   // if the site root folder is selected.
  100.   for (i=0; i < fileList.length; i++)
  101.   {
  102.     var file = fileList[i];
  103.     var urlPrefix = "file:///";
  104.     var strTemp = file.substr(urlPrefix.length);
  105.     if(strTemp.indexOf("/") == -1 || file == dw.getSiteRoot().substring(0,dw.getSiteRoot().length-1))
  106.       return false;
  107.   }
  108.   
  109.   return ((fileList.length == 1)? fileList[0] : false);
  110. }
  111.